/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modulos.paciente.vista;

import basedatos.OperacionesBD;
import basedatos.PacienteBD;
import javax.swing.JOptionPane;
import modulos.paciente.modelo.Paciente;
import modelo.Persona;
import vista.modelo.OperacionesVarias;

/**
 *
 * @author med
 */
public class iFrmPaciente extends javax.swing.JInternalFrame {

    private Paciente mdfPaciente;

    public iFrmPaciente() {
        initComponents();
        setEnableAll(false);
        txtDiscapacidad.setEnabled(false);
        OperacionesVarias.centrar(this);
    }

    public iFrmPaciente(Paciente mdfPaciente) {
        initComponents();
        this.mdfPaciente = mdfPaciente;
        setPaciente();
        this.btnNuevo.setVisible(false);
        OperacionesVarias.centrar(this);
    
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grpradBuscar = new javax.swing.ButtonGroup();
        btnCerrar = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        btnNuevo = new javax.swing.JButton();
        pnlBase = new javax.swing.JPanel();
        txtDiscapacidad = new javax.swing.JTextField();
        lblHc = new javax.swing.JLabel();
        pnlIdentificacion = new javax.swing.JPanel();
        lblCedula = new javax.swing.JLabel();
        lblNombre = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        lblApellido = new javax.swing.JLabel();
        txtApellido = new javax.swing.JTextField();
        chkCedulaProv = new javax.swing.JCheckBox();
        txtCedula = new javax.swing.JTextField();
        pnlPropiedad1 = new javax.swing.JPanel();
        cmbGenero = new javax.swing.JComboBox();
        cmbTipoSangre = new javax.swing.JComboBox();
        cmbEcivil = new javax.swing.JComboBox();
        txtLugarNace = new javax.swing.JTextField();
        lblTipoSangre = new javax.swing.JLabel();
        lblFechaNace = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtEdad = new javax.swing.JTextField();
        lblTipoSangre1 = new javax.swing.JLabel();
        cmbRaza = new javax.swing.JComboBox();
        fechaNace = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        txtLugarResi = new javax.swing.JTextField();
        pnlLaboral = new javax.swing.JPanel();
        lblInstruccion = new javax.swing.JLabel();
        cmbInstruccion = new javax.swing.JComboBox();
        lblProfesion = new javax.swing.JLabel();
        txtProfesion = new javax.swing.JTextField();
        lblOcupacion = new javax.swing.JLabel();
        txtOcupacion = new javax.swing.JTextField();
        pnlUbicacion = new javax.swing.JPanel();
        txtTelefono = new javax.swing.JTextField();
        lblTelefono = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        lblDireccion = new javax.swing.JLabel();
        txtMovil = new javax.swing.JTextField();
        lblMovil = new javax.swing.JLabel();
        lblSeguro = new javax.swing.JLabel();
        cmbSeguro = new javax.swing.JComboBox();
        chkDiscapacidad = new javax.swing.JCheckBox();

        setClosable(true);
        setTitle("Paciente");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/PatientMale.png"))); // NOI18N
        setName("iFramePaciente");
        setVisible(true);

        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/agt_home.png"))); // NOI18N
        btnCerrar.setText("Cerrar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/filesave.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jpgs/add.png"))); // NOI18N
        btnNuevo.setText("Nuevo");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        pnlBase.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        pnlBase.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        txtDiscapacidad.setText("Ninguna");
        txtDiscapacidad.setEnabled(false);
        txtDiscapacidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDiscapacidadKeyTyped(evt);
            }
        });
        pnlBase.add(txtDiscapacidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 400, 590, -1));
        pnlBase.add(lblHc, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        pnlIdentificacion.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlIdentificacion.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblCedula.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N
        lblCedula.setText("Identificacion");
        pnlIdentificacion.add(lblCedula, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 10, -1, -1));

        lblNombre.setText("Nombres:");
        pnlIdentificacion.add(lblNombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 10, -1, -1));

        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });
        pnlIdentificacion.add(txtNombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 30, 300, -1));

        lblApellido.setText("Apellidos:");
        lblApellido.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        pnlIdentificacion.add(lblApellido, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 10, -1, -1));

        txtApellido.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApellidoKeyTyped(evt);
            }
        });
        pnlIdentificacion.add(txtApellido, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 30, 300, -1));

        chkCedulaProv.setFont(new java.awt.Font("Ubuntu", 0, 11)); // NOI18N
        chkCedulaProv.setText("Id. Prov.");
        chkCedulaProv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkCedulaProvActionPerformed(evt);
            }
        });
        pnlIdentificacion.add(chkCedulaProv, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 30, -1, -1));

        txtCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCedulaKeyTyped(evt);
            }
        });
        pnlIdentificacion.add(txtCedula, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 30, 120, -1));

        pnlBase.add(pnlIdentificacion, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 820, 70));

        pnlPropiedad1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlPropiedad1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cmbGenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Femenino" }));
        pnlPropiedad1.add(cmbGenero, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 30, 120, -1));

        cmbTipoSangre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Desc", "ORH+", "ORH-", "ARH+", "ARH-", "BRH+", "BRH-", "ABRH+", "ABRH-" }));
        pnlPropiedad1.add(cmbTipoSangre, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 80, 120, -1));

        cmbEcivil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Soltero/a", "Casado/a", "Divorciado/a", "Viudo/a", "Union-libre" }));
        pnlPropiedad1.add(cmbEcivil, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 30, 130, -1));

        txtLugarNace.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtLugarNaceFocusGained(evt);
            }
        });
        txtLugarNace.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtLugarNaceKeyTyped(evt);
            }
        });
        pnlPropiedad1.add(txtLugarNace, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 30, 230, -1));

        lblTipoSangre.setText("G. sanguíneo:");
        pnlPropiedad1.add(lblTipoSangre, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 60, -1, -1));

        lblFechaNace.setText("Fecha nacim.");
        pnlPropiedad1.add(lblFechaNace, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        jLabel7.setText("Lugar Nacimiento:");
        pnlPropiedad1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 10, -1, -1));

        jLabel15.setText("Género:");
        pnlPropiedad1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 10, -1, -1));

        jLabel1.setText("Estado civil:");
        pnlPropiedad1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 10, -1, -1));

        jLabel8.setText("Lugar Residencia:");
        pnlPropiedad1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 60, -1, -1));

        txtEdad.setEditable(false);
        txtEdad.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N
        txtEdad.setFocusable(false);
        pnlPropiedad1.add(txtEdad, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, 200, -1));

        lblTipoSangre1.setText("Raza:");
        pnlPropiedad1.add(lblTipoSangre1, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 60, -1, -1));

        cmbRaza.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mestizo", "AfroEcuatoriano", "Indigena" }));
        pnlPropiedad1.add(cmbRaza, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 80, 130, -1));
        pnlPropiedad1.add(fechaNace, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 200, 30));

        jLabel3.setText("Edad");
        pnlPropiedad1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        txtLugarResi.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtLugarResiKeyTyped(evt);
            }
        });
        pnlPropiedad1.add(txtLugarResi, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 80, 230, -1));

        pnlBase.add(pnlPropiedad1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 820, 120));

        pnlLaboral.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblInstruccion.setText("Instrucción:");

        cmbInstruccion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ninguna", "Primaria", "Secundaria", "Superior" }));

        lblProfesion.setText("Profesión:");

        txtProfesion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtProfesionKeyTyped(evt);
            }
        });

        lblOcupacion.setText("Ocupacion:");

        txtOcupacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtOcupacionKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout pnlLaboralLayout = new javax.swing.GroupLayout(pnlLaboral);
        pnlLaboral.setLayout(pnlLaboralLayout);
        pnlLaboralLayout.setHorizontalGroup(
            pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlLaboralLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbInstruccion, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblInstruccion))
                .addGap(18, 18, 18)
                .addGroup(pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblProfesion)
                    .addComponent(txtProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLaboralLayout.createSequentialGroup()
                        .addComponent(lblOcupacion)
                        .addGap(0, 306, Short.MAX_VALUE))
                    .addComponent(txtOcupacion))
                .addContainerGap())
        );
        pnlLaboralLayout.setVerticalGroup(
            pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlLaboralLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblInstruccion)
                    .addComponent(lblProfesion)
                    .addComponent(lblOcupacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLaboralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cmbInstruccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pnlBase.add(pnlLaboral, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 290, 820, 80));

        pnlUbicacion.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyTyped(evt);
            }
        });

        lblTelefono.setText("Teléfono:");

        lblDireccion.setText("Dirección:");

        txtMovil.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtMovilKeyTyped(evt);
            }
        });

        lblMovil.setText("Movil:");

        javax.swing.GroupLayout pnlUbicacionLayout = new javax.swing.GroupLayout(pnlUbicacion);
        pnlUbicacion.setLayout(pnlUbicacionLayout);
        pnlUbicacionLayout.setHorizontalGroup(
            pnlUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlUbicacionLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(pnlUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlUbicacionLayout.createSequentialGroup()
                        .addComponent(lblDireccion)
                        .addGap(0, 455, Short.MAX_VALUE))
                    .addComponent(txtDireccion))
                .addGap(18, 18, 18)
                .addGroup(pnlUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTelefono))
                .addGap(19, 19, 19)
                .addGroup(pnlUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtMovil, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblMovil))
                .addContainerGap())
        );
        pnlUbicacionLayout.setVerticalGroup(
            pnlUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlUbicacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTelefono)
                    .addComponent(lblDireccion)
                    .addComponent(lblMovil))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlUbicacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMovil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pnlBase.add(pnlUbicacion, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, 820, 80));

        lblSeguro.setText("Seguro social:");
        pnlBase.add(lblSeguro, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 380, -1, -1));

        cmbSeguro.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ninguno", "General", "Voluntario", "Campesino", "Privado" }));
        pnlBase.add(cmbSeguro, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 400, 130, -1));

        chkDiscapacidad.setText("Discapacidad:");
        chkDiscapacidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkDiscapacidadActionPerformed(evt);
            }
        });
        pnlBase.add(chkDiscapacidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 380, -1, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(btnNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(pnlBase, javax.swing.GroupLayout.DEFAULT_SIZE, 851, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(pnlBase, javax.swing.GroupLayout.PREFERRED_SIZE, 447, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar)
                    .addComponent(btnNuevo)
                    .addComponent(btnCerrar))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        this.iniciarlizarForm();

    }//GEN-LAST:event_btnNuevoActionPerformed

    private void iniciarlizarForm() {
        txtCedula.setText("");
        txtCedula.setEditable(true);
        txtNombre.setText("");
        txtApellido.setText("");
        txtDireccion.setText("");
        fechaNace.setDate(new java.util.Date()); ///poner la fecha actual del sistema
        txtLugarNace.setText("");
        cmbGenero.setSelectedIndex(0);
        cmbTipoSangre.setSelectedIndex(0);
        cmbEcivil.setSelectedIndex(0);
        txtDireccion.setText("");
        txtTelefono.setText("");
        txtMovil.setText("");
        cmbInstruccion.setSelectedIndex(0);
        txtProfesion.setText("");;
        txtOcupacion.setText("");
        txtLugarResi.setText("");
        txtEdad.setText("");
        cmbSeguro.setSelectedIndex(0);
        cmbTipoSangre.setSelectedIndex(0);
        txtDiscapacidad.setText("Ninguna");
        chkCedulaProv.setSelected(false);
        chkDiscapacidad.setSelected(false);
        this.setEnableAll(true);
        chkCedulaProv.transferFocus();
    }

    private void setPaciente() {
        if (Persona.validadorDeCedula(mdfPaciente.getCedula())) {
            chkCedulaProv.setEnabled(false);
            txtCedula.setEnabled(false);
        }

        txtCedula.setText(mdfPaciente.getCedula());
        txtNombre.setEnabled(false);
        txtNombre.setText(mdfPaciente.getNombre());
        txtApellido.setEnabled(false);
        txtApellido.setText(mdfPaciente.getApellido());
        fechaNace.setEnabled(false);
        fechaNace.setDate(mdfPaciente.getFechaNace());
        txtLugarNace.setEnabled(false);
        txtLugarNace.setText(mdfPaciente.getLugarNace());
        cmbGenero.setEnabled(false);
        cmbGenero.setSelectedItem(mdfPaciente.getGenero());
        if (!mdfPaciente.gettSangre().equalsIgnoreCase("Desc")) {
            cmbTipoSangre.setEnabled(false);
        }
        cmbTipoSangre.setSelectedItem(mdfPaciente.gettSangre());
        cmbEcivil.setSelectedItem(mdfPaciente.geteCivil());
        txtDireccion.setText(mdfPaciente.getDireccion());
        txtTelefono.setText(mdfPaciente.getTelefono());
        txtMovil.setText(mdfPaciente.getCelular());
        cmbInstruccion.setSelectedItem(mdfPaciente.getInstruccion());
        txtProfesion.setText(mdfPaciente.getProfeccion());
        txtOcupacion.setText(mdfPaciente.getOcupacion());
        cmbSeguro.setSelectedItem(mdfPaciente.getSeguro());
        txtDiscapacidad.setText(mdfPaciente.getDiscapacidad());
        btnGuardar.setEnabled(true);
        btnGuardar.setText("Modificar");
        btnCerrar.setText("Cancelar");
        chkDiscapacidad.setEnabled(true);
        cmbRaza.setEnabled(false);
        cmbRaza.setSelectedItem(mdfPaciente.getRaza());
        txtEdad.setText(Persona.calcularEdad(mdfPaciente.getFechaNace()));
        txtLugarResi.setText(mdfPaciente.getLugarResi());

    }

    private Paciente getPaciente(Paciente p) {
        
        if (chkCedulaProv.isSelected()) {
            if(p.getCedula().isEmpty())
            p.setCedula(""+(OperacionesBD.listar("Paciente").size() + 1));
        } else {
            p.setCedula(txtCedula.getText());
        }
        p.setNumeroHC("HC"+(OperacionesBD.listar("Paciente").size()+1));
        p.setNombre(txtNombre.getText());
        p.setApellido(txtApellido.getText());
        p.setFechaNace(fechaNace.getDate());
        p.setLugarNace(txtLugarNace.getText());
        p.setGenero(cmbGenero.getSelectedItem().toString());
        p.settSangre(cmbTipoSangre.getSelectedItem().toString());
        p.seteCivil(cmbEcivil.getSelectedItem().toString());
        p.setDireccion(txtDireccion.getText());
        p.setTelefono(txtTelefono.getText());
        p.setCelular(txtMovil.getText());
        p.setInstruccion(cmbInstruccion.getSelectedItem().toString());
        p.setProfeccion(txtProfesion.getText());
        p.setOcupacion(txtOcupacion.getText());
        p.setSeguro(cmbSeguro.getSelectedItem().toString());
        p.setDiscapacidad(txtDiscapacidad.getText());
        p.setLugarResi(txtLugarResi.getText());
        p.setRaza(cmbRaza.getSelectedItem().toString());
        return p;
    }

    private void setEnableAll(boolean enable) {
        txtCedula.setEnabled(enable);
        txtNombre.setEnabled(enable);
        txtApellido.setEnabled(enable);
        fechaNace.setEnabled(enable);
        txtLugarNace.setEnabled(enable);
        cmbGenero.setEnabled(enable);
        cmbTipoSangre.setEnabled(enable);
        cmbEcivil.setEnabled(enable);
        txtDireccion.setEnabled(enable);
        txtTelefono.setEnabled(enable);
        txtMovil.setEnabled(enable);
        cmbInstruccion.setEnabled(enable);
        txtProfesion.setEnabled(enable);
        txtOcupacion.setEnabled(enable);
        cmbSeguro.setEnabled(enable);
        txtDiscapacidad.setEnabled(!enable);
        btnGuardar.setEnabled(enable);
        chkCedulaProv.setEnabled(enable);
        chkDiscapacidad.setEnabled(enable);
        cmbRaza.setEnabled(enable);
        txtEdad.setEnabled(enable);
        txtLugarResi.setEnabled(enable);
    }
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed

        try {
            if (btnGuardar.getText().trim().compareTo("Guardar") == 0) {

                if (txtNombre.getText().trim().compareTo("") != 0 && txtApellido.getText().trim().compareTo("") != 0)//change lngt
                {
                    if (!chkCedulaProv.isSelected()) {
                        if (txtCedula.getText().trim().compareTo("") != 0) {
                            if (Persona.validadorDeCedula(txtCedula.getText().trim())) {
                                if (!PacienteBD.existePaciente(txtCedula.getText().trim())) {
                                    if (OperacionesBD.guardar(this.getPaciente(new Paciente()))) {
                                        this.setEnableAll(false);
                                        txtDiscapacidad.setEnabled(false);
                                        JOptionPane.showMessageDialog(null, "Datos del paciente guardados correctamente ...", "Guardar", JOptionPane.INFORMATION_MESSAGE);
                                    } else {
                                        JOptionPane.showMessageDialog(null, "Datos del paciente no se han podido guardar ...", "Guardar", JOptionPane.ERROR_MESSAGE);
                                    }
                                } else {
                                    txtNombre.transferFocusBackward();
                                }
                            } else {
                                JOptionPane.showMessageDialog(null, "El numero de cedula ingresado no es valido: \n" + txtCedula.getText(), "Guardar", JOptionPane.WARNING_MESSAGE);
                                txtNombre.transferFocusBackward();

                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "El campo Cédula del paciente es obligatorio", "Guardar", JOptionPane.WARNING_MESSAGE);
                            txtNombre.transferFocusBackward();
                        }
                    } else {
                        if (OperacionesBD.guardar(this.getPaciente(new Paciente()))) {
                            this.setEnableAll(false);
                            txtDiscapacidad.setEnabled(false);
                            JOptionPane.showMessageDialog(null, "Datos del paciente guardados correctamente ...", "Guardar", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(null, "Datos del paciente no se han podido guardar ...", "Guardar", JOptionPane.ERROR_MESSAGE);
                        }

                    }
                    //guardar              
                } else {
                    JOptionPane.showMessageDialog(null, "Los campos Nombre y Apellido del paciente son obligatorios", "Guardar", JOptionPane.WARNING_MESSAGE);
                }

            } else {//up    

                if (!chkCedulaProv.isSelected()) {
                    if (txtCedula.getText().trim().compareTo("") != 0) {
                        if (Persona.validadorDeCedula(txtCedula.getText().trim())) {
                            if (!txtCedula.getText().trim().equalsIgnoreCase(mdfPaciente.getCedula())) {
                                if (!PacienteBD.existePaciente(txtCedula.getText().trim())) {
                                    if (OperacionesBD.modificar(this.getPaciente(mdfPaciente))) {
                                        iFrmLstPaciente.setPaciente();
                                        JOptionPane.showMessageDialog(null, "Los datos se han actualizado correctamente ...", "Actualizar", JOptionPane.INFORMATION_MESSAGE);
                                        dispose();
                                    } else {
                                        JOptionPane.showMessageDialog(null, "Los datos del paciente no se han podido actualizar ...", "Actualizar", JOptionPane.ERROR_MESSAGE);
                                    }
                                } else {
                                    txtNombre.transferFocusBackward();
                                }
                            } else {
                                if (OperacionesBD.modificar(this.getPaciente(mdfPaciente))) {
                                    iFrmLstPaciente.setPaciente();
                                    JOptionPane.showMessageDialog(null, "Los datos se han actualizado correctamente ...", "Actualizar", JOptionPane.INFORMATION_MESSAGE);
                                    dispose();
                                } else {
                                    JOptionPane.showMessageDialog(null, "Los datos del paciente no se han podido actualizar ...", "Actualizar", JOptionPane.ERROR_MESSAGE);
                                }
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "El numero de cedula ingresado no es valido: \n" + txtCedula.getText(), "Guardar", JOptionPane.WARNING_MESSAGE);
                            txtNombre.transferFocusBackward();

                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "El campo Cédula del paciente es obligatorio", "Guardar", JOptionPane.WARNING_MESSAGE);
                        txtNombre.transferFocusBackward();
                    }
                } else {
                    if (OperacionesBD.modificar(this.getPaciente(mdfPaciente))) {
                        iFrmLstPaciente.setPaciente();
                        JOptionPane.showMessageDialog(null, "Los datos se han actualizado correctamente ...", "Actualizar", JOptionPane.INFORMATION_MESSAGE);
                        dispose();
                    } else {
                        JOptionPane.showMessageDialog(null, "Los datos del paciente no se han podido actualizar ...", "Actualizar", JOptionPane.ERROR_MESSAGE);
                    }
                }

            }//up

        } catch (Exception ex) {
            System.out.println(ex.getMessage());

        }

    }//GEN-LAST:event_btnGuardarActionPerformed

    private void chkDiscapacidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkDiscapacidadActionPerformed
        if (chkDiscapacidad.isSelected()) {
            txtDiscapacidad.setEnabled(true);
            txtDiscapacidad.setSelectionEnd(txtDiscapacidad.getText().length() - 1);
            txtDiscapacidad.setSelectionStart(0);
            cmbSeguro.transferFocus();
        } else {
            txtDiscapacidad.setEnabled(false);
            txtDiscapacidad.setText("Ninguna");
            btnNuevo.transferFocus();
        }
    }//GEN-LAST:event_chkDiscapacidadActionPerformed

    private void chkCedulaProvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkCedulaProvActionPerformed
        if (chkCedulaProv.isSelected()) {
            txtCedula.setEditable(false);
            txtCedula.transferFocus();
        } else {
            txtCedula.setText("");
            txtCedula.setEditable(true);
            chkCedulaProv.transferFocus();
        }
    }//GEN-LAST:event_chkCedulaProvActionPerformed

    private void txtLugarNaceFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtLugarNaceFocusGained
        txtEdad.setText(Persona.calcularEdad(fechaNace.getDate()));
    }//GEN-LAST:event_txtLugarNaceFocusGained

    private void txtCedulaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCedulaKeyTyped
        OperacionesVarias.ingresoNumCedula(evt, txtCedula.getText());
    }//GEN-LAST:event_txtCedulaKeyTyped

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
        OperacionesVarias.ingresoSoloLetras(evt);
    }//GEN-LAST:event_txtNombreKeyTyped

    private void txtApellidoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoKeyTyped
        OperacionesVarias.ingresoSoloLetras(evt);
    }//GEN-LAST:event_txtApellidoKeyTyped

    private void txtLugarNaceKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtLugarNaceKeyTyped
        OperacionesVarias.ingresoSoloLetras(evt);
    }//GEN-LAST:event_txtLugarNaceKeyTyped

    private void txtLugarResiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtLugarResiKeyTyped
        OperacionesVarias.ingresoSoloLetras(evt);
    }//GEN-LAST:event_txtLugarResiKeyTyped

    private void txtTelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyTyped
        OperacionesVarias.ingresoSoloNumeros(evt);
    }//GEN-LAST:event_txtTelefonoKeyTyped

    private void txtMovilKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMovilKeyTyped
        OperacionesVarias.ingresoSoloNumeros(evt);
    }//GEN-LAST:event_txtMovilKeyTyped

    private void txtProfesionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProfesionKeyTyped
        OperacionesVarias.ingresoSoloLetras(evt);
    }//GEN-LAST:event_txtProfesionKeyTyped

    private void txtOcupacionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtOcupacionKeyTyped
        OperacionesVarias.ingresoSoloLetras(evt);
    }//GEN-LAST:event_txtOcupacionKeyTyped

    private void txtDiscapacidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDiscapacidadKeyTyped
        OperacionesVarias.ingresoSoloLetras(evt);
    }//GEN-LAST:event_txtDiscapacidadKeyTyped
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JCheckBox chkCedulaProv;
    private javax.swing.JCheckBox chkDiscapacidad;
    private javax.swing.JComboBox cmbEcivil;
    private javax.swing.JComboBox cmbGenero;
    private javax.swing.JComboBox cmbInstruccion;
    private javax.swing.JComboBox cmbRaza;
    private javax.swing.JComboBox cmbSeguro;
    private javax.swing.JComboBox cmbTipoSangre;
    private com.toedter.calendar.JDateChooser fechaNace;
    private javax.swing.ButtonGroup grpradBuscar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel lblApellido;
    private javax.swing.JLabel lblCedula;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblFechaNace;
    private javax.swing.JLabel lblHc;
    private javax.swing.JLabel lblInstruccion;
    private javax.swing.JLabel lblMovil;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblOcupacion;
    private javax.swing.JLabel lblProfesion;
    private javax.swing.JLabel lblSeguro;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JLabel lblTipoSangre;
    private javax.swing.JLabel lblTipoSangre1;
    private javax.swing.JPanel pnlBase;
    private javax.swing.JPanel pnlIdentificacion;
    private javax.swing.JPanel pnlLaboral;
    private javax.swing.JPanel pnlPropiedad1;
    private javax.swing.JPanel pnlUbicacion;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtDiscapacidad;
    private javax.swing.JTextField txtEdad;
    private javax.swing.JTextField txtLugarNace;
    private javax.swing.JTextField txtLugarResi;
    private javax.swing.JTextField txtMovil;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtOcupacion;
    private javax.swing.JTextField txtProfesion;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration//GEN-END:variables
}
